<template>
  <div id="record">
    <c-title :hide="false" :text="`${typeClass}记录`"></c-title>
    <recordlist :typeClass="type" :show="show" :info="rankingList" :count="sub_team_count" :usable_name="usable_name"></recordlist>
  </div>
</template>
<script>
import { scrollMixin } from "utils/mixin";
import recordlist from "./components/recordList.vue";
export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      typeClass: "",
      type: "",
      url: "",
      sub_team_count: "",
      show: false,
      reward_id: "",
      rankingList: [],
      usable_name:'',

      isLoadMore: true,
      page: 1,
      total_page: 0,

      otherJson: {}
    };
  },
  activated() {
    this.init();
    this.type = this.$route.params.type;
    this.reward_id = this.$route.params.id;
    if (this.type == 1) {
      // 奖励记录
      this.typeClass = "奖励";
      this.url = "plugin.task-package.frontend.daily.reward-record";
      this.otherJson = {
        record_id: this.$route.params.id
      };
    } else if (this.type == 2) {
      this.typeClass = "总贡献值";
      this.url = "plugin.task-package.frontend.active-value.get-list";
    } else if (this.type == 3) {
      this.typeClass = "贡献值";
      this.url = "plugin.task-package.frontend.record.contribution-value";
    } else if (this.type == 4) {
      this.typeClass = "复活";
      this.url = "plugin.task-package.frontend.recovery.recovery-list";
    } else if (this.type == 5) {
      this.typeClass = "手续费";
      this.url = "plugin.task-package.frontend.record.procedures-fee";
    } else if (this.type == 6) {
      this.typeClass = "平台流水";
      this.url = "plugin.task-package.frontend.record.platform-flow";
    } else if (this.type == 7) {
      this.typeClass = "下级团队";
      this.url = "plugin.task-package.frontend.index.sub-team";
    } else if (this.type == 8) {
      this.typeClass = "兑换";
      this.url = "plugin.task-package.frontend.record.get-list";
    }
    this.fun.setWXTitle(this.typeClass);
    this.getData();
  },
  methods: {
    init() {
      this.page = 1;
      this.isLoadMore = true;
      this.total_page = 0;
    },
    getData() {
      let json = {
        page: this.page,
        ...this.otherJson
      };
      $http.get(this.url, json, "加载中..").then(response => {
        if (response.result == 1) {
          let res = response.data;
          if (this.type == 4) {
            this.rankingList = res;
          } else if (this.type == 1 || this.type == 8) {
            this.rankingList = res.data;
          } else {
            this.rankingList = res.list;
          }
          if (this.type == 7) {
            this.sub_team_count = response.data.sub_team_count;
          } else if (this.type == 2) {
            this.sub_team_count = response.data.total_amount;
          } else if (this.type == 3) {
            this.sub_team_count = response.data.total;
          } else if (this.type == 5 || this.type == 6) {
            this.sub_team_count = response.data.total;
            if (this.type == 6) {
              this.show = response.data.show;
              this.usable_name = response.data.usable_name;
            }
          }else if (this.type == 8){
            this.usable_name = res.usable_name;
          }
          console.log(this.rankingList, "rankingList");
          this.isLoadMore = true;
          if (this.type == 4) {
            this.total_page = res.last_page;
          } else if (this.type == 1 || this.type == 8) {
            this.total_page = res.last_page;
          } else {
            this.total_page = res.list.last_page;
          }
          if (!this.total_page) {
            this.page = 0;
          }
        } else {
          this.page = this.page - 1;
          this.isLoadMore = false;
          this.$dialog.alert({
            message: response.msg
          });
        }
      });
    },
    //获取更多数据
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        let json = {
          page: this.page,
          ...this.otherJson
        };
        $http.post(this.url, json, "加载中").then(
          res => {
            this.isLoadMore = true;
            if (res.result === 1) {
              let myData = [];
              if (this.type == 4) {
                myData = res.data.data;
                this.total_page = res.data.last_page;
                this.rankingList.data = [...this.rankingList.data, ...myData]; //数组拼接
              } else if (this.type == 1|| this.type == 8) {
                myData = res.data.data;
                this.total_page = res.data.last_page;
                this.rankingList = [...this.rankingList, ...myData]; //数组拼接
              } else {
                myData = res.data.list.data;
                this.total_page = res.data.list.last_page;
                this.rankingList.data = [...this.rankingList.data, ...myData]; //数组拼接
              }
              console.log(this.rankingList);
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          },
          function (response) {
            // error callback
          }
        );
      }
    }
  },
  components: { recordlist }
};
</script>
<style scoped>
</style>